package io.lvdaxian.mybatis10.scripting.xmltags;

import io.lvdaxian.mybatis10.executor.parameter.ParameterHandler;
import io.lvdaxian.mybatis10.mapping.BoundSql;
import io.lvdaxian.mybatis10.mapping.MappedStatement;
import io.lvdaxian.mybatis10.mapping.SqlSource;
import io.lvdaxian.mybatis10.scripting.LanguageDriver;
import io.lvdaxian.mybatis10.scripting.defaults.DefaultParameterHandler;
import io.lvdaxian.mybatis10.session.Configuration;
import org.dom4j.Element;

/**
 * xml 语言驱动
 *
 * @author lihh
 */
public class XMLLanguageDriver implements LanguageDriver {
  
  @Override
  public SqlSource createSqlSource(Configuration configuration, Element script, Class<?> parameterType) {
    XMLScriptBuilder xmlScriptBuilder = new XMLScriptBuilder(configuration, script, parameterType);
    return xmlScriptBuilder.parseScriptNode();
  }
  
  /**
   * 这是创建了一个 参数处理器
   *
   * @param mappedStatement mapped statement 语句
   * @param parameterObject 参数对象
   * @param boundSql        sql
   * @return
   * @author lihh
   */
  @Override
  public ParameterHandler createParameterHandler(MappedStatement mappedStatement, Object parameterObject, BoundSql boundSql) {
    return new DefaultParameterHandler(mappedStatement, parameterObject, boundSql);
  }
}
